package com.lingx.model.impl.interpreter;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.lingx.model.impl.AbstractInterpreter;
//@Component
public class ChatMsgInterpreter  extends AbstractInterpreter{
	private static final long serialVersionUID = 6428029760172871233L;

	public ChatMsgInterpreter() {
		super("ChatMsgInterpreter","聊天消息格式转换");
	}
	@Override
	public Object input(Object value) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object output(Object value) throws Exception {
		if(value!=null&&value.toString().charAt(0)=='{') {
			Map<String,Object> map=(Map<String,Object>)JSON.parse(value.toString());
			Map<String,Object> msg=(Map<String,Object>)map.get("msg");
			String type=msg.get("type").toString();
			String ret="";
			switch(type) {
			case "1":
				ret=msg.get("content").toString();
				break;
			case "2":
				ret="<a href='"+msg.get("url").toString()+"' target='_blank'>图片预览</a>";
				break;
			case "3":
				ret="<a href='"+msg.get("url").toString()+"' target='_blank'>语音消息</a>";
				break;
			case "4":
				ret=msg.get("content").toString();
				break;
			case "5":
				ret="文件消息";
				break;
			}
			return ret;
		} 
		return value;
	}

}
